// 云函数入口文件
const cloud = require('wx-server-sdk')
const mysql = require('mysql2/promise')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  var userid = event.id;
  try {
    const connection = await mysql.createConnection({
      host: "47.115.22.254",
      port: 3306,
      database: "EPMS",
      user: "root",
      password: "1234"
    })
    var sql = 'SELECT * FROM INorOUT WHERE userid="'+userid+'";';
    var [rows, fields] = await connection.execute(sql);
    // var rows = await connection.execute(sql);
    return rows;
    conection.end();
  } catch (err) {
    return err
  }
}